﻿Imports TMySQL
Public Class frmDatabasePrivileges
    Private _PrivList As TMyDatabasePrivilegesList
    Private Sub New()
        ' この呼び出しは、Windows フォーム デザイナで必要です。
        InitializeComponent()
        ' InitializeComponent() 呼び出しの後で初期化を追加します。
    End Sub
    Public Sub New(ByVal APrivList As TMyDatabasePrivilegesList)
        Me.New()
        _PrivList = APrivList
        InitFrm()
    End Sub
    Private Sub InitFrm()
        lstDatabase.Items.Clear()
        For i As Integer = 0 To frmMain.DatabaseList.Count - 1
            lstDatabase.Items.Add(frmMain.DatabaseList(i).DatabaseName)
        Next
    End Sub
    Private Sub InitCheck()
        chkAlter.Checked = False
        chkAlterRoutine.Checked = False
        chkCreate.Checked = False
        chkCreateRoutine.Checked = False
        chkCreateTemporaryTables.Checked = False
        chkCreateView.Checked = False
        chkDelete.Checked = False
        chkDrop.Checked = False
        chkEvent.Checked = False
        chkExecute.Checked = False
        chkGrant.Checked = False
        chkIndex.Checked = False
        chkInsert.Checked = False
        chkLockTables.Checked = False
        chkReferences.Checked = False
        chkSelect.Checked = False
        chkShowView.Checked = False
        chkTrigger.Checked = False
        chkUpdate.Checked = False
    End Sub

    Private Sub ShowPrivs(ByVal APriv As TMyDatabasePrivileges)
        chkSelect.Checked = APriv.SelectPriv
        chkInsert.Checked = APriv.InsertPriv
        chkUpdate.Checked = APriv.UpdatePriv
        chkDelete.Checked = APriv.DeletePriv

        chkCreate.Checked = APriv.CreatePriv
        chkAlter.Checked = APriv.AlterPriv
        chkIndex.Checked = APriv.IndexPriv
        chkDrop.Checked = APriv.DropPriv
        chkCreateTemporaryTables.Checked = APriv.CreatePriv
        chkShowView.Checked = APriv.ShowViewPriv
        chkCreateRoutine.Checked = APriv.CreateRoutinePriv
        chkAlterRoutine.Checked = APriv.AlterRoutinePriv
        chkExecute.Checked = APriv.ExecutePriv
        chkCreateView.Checked = APriv.CreateViewPriv
        chkEvent.Checked = APriv.EventPriv
        chkTrigger.Checked = APriv.TriggerPriv

        chkGrant.Checked = APriv.GrantPriv
        chkLockTables.Checked = APriv.Lock_tablesPriv
        chkReferences.Checked = APriv.ReferencesPriv
    End Sub

    Private Sub lstDatabase_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDatabase.SelectedIndexChanged
        Cursor.Current = Cursors.WaitCursor
        Try
            InitCheck()
            Dim item As TMyDatabasePrivileges = _PrivList(lstDatabase.SelectedItem)
            If item IsNot Nothing Then
                ShowPrivs(item)
            End If
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Sub
End Class